package com.usian.article.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.article.AuthorControllerApi;
import com.usian.article.service.AuthorService;
import com.usian.article.service.impl.AuthorServiceImpl;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/v1/author")
public class AuthorController implements AuthorControllerApi {
    @Autowired
    private AuthorServiceImpl service;

    @GetMapping("findByUserId/{id}")
    @Override
    public ApAuthor findByUserId(@PathVariable("id") Integer id) {
        return id !=null ?service.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getId,id)):null;
    }

    @PostMapping("save")
    @Override
    public ResponseResult save(@RequestBody ApAuthor author) {
        if (author==null){
            return service.paramError;
        }
            service.save(author);
        return ResponseResult.okResult(author);
    }
}
